package com.basker.pisces.springcloud.locale;

import java.util.Locale;

import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;

import com.basker.pisces.resource.StringResources;

/**
 * 验证消息拦截器，用于翻译验证消息
 *
 * @author hangwen
 */
public class LocaleValidationMessageInterpolator extends ParameterMessageInterpolator {

    @Override
    public String interpolate(String messageTemplate, Context context, Locale locale) {
        if (messageTemplate == null) {
            return messageTemplate;
        }

        String resolvedMessageTemplate = StringResources.resolve(messageTemplate, locale, context.getValidatedValue());
        resolvedMessageTemplate = super.interpolate(resolvedMessageTemplate, context, locale);

        return resolvedMessageTemplate;
    }

}
